﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace docmgr.WinForm
{
    public partial class PostionOperation : Form
    {
        DataTable pos = null;


        BLL.Position posbll = new BLL.Position();
        public PostionOperation()
        {
            InitializeComponent();
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(134)));

        }

        public PostionOperation(String key)
        {
            InitializeComponent();
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(134)));

            pos = posbll.GetModel(key);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (Nametbx.Text == null)
            {
                MessageBox.Show("岗位名称不能为空");
                return;
            }

            if (pos == null)
            {
                String sqlStr = String.Format("insert [Position] (Name,Remark) values ('{0}','{1}')", Nametbx.Text, Remarktbx.Text);
                SQLHelper.ExecuteSql(SQLHelper.connString, sqlStr);
            }
            else
            {
                pos.Rows[0]["Name"] = Nametbx.Text;
                pos.Rows[0]["Remark"] = Remarktbx.Text;
                posbll.Update(pos);
            }
            MessageBox.Show("操作成功！");
            this.Close();
        }

        private void PostionOperation_Load(object sender, EventArgs e)
        {
            if (pos == null)
                button2.Visible = false;

            if (pos != null)
            {
                Nametbx.Text = (String)pos.Rows[0]["Name"];
                Remarktbx.Text = pos.Rows[0]["Remark"].ToString();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            AddPositionAuthority frm = new AddPositionAuthority(pos.Rows[0]["ID"]);
            frm.WindowState = FormWindowState.Normal;
            frm.StartPosition = FormStartPosition.CenterScreen;
            if (frm.ShowDialog() == DialogResult.OK)
            {

            }

            MessageBox.Show("修改完成");
            this.Close();
        }
    }
}
